import { ref, watch, type ComputedRef } from 'vue';

const colHeight = ref<Record<string, number>>({});

export default function useColHeight(props: {
  columns: ComputedRef<number>;
  data: ComputedRef<Record<string, any>[] | null>;
}) {
  updateColHeight();

  watch(
    () => props.data.value,
    () => {
      setTimeout(() => {
        updateColHeight();
      }, 100);
    }
  );

  watch(
    () => props.columns.value,
    () => {
      setTimeout(() => {
        updateColHeight();
      }, 100);
    }
  );

  function updateColHeight() {
    colHeight.value = {};

    for (let i = 0; i < props.columns.value; i++) {
      colHeight.value[i] = 0;
    }
  }

  return { colHeight };
}
